<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>悦听player</title>
  <!-- 样式 -->
  <link rel="stylesheet" href="./css/index.css">
</head>
<body>
  <div class="wrap">
    <!-- 播放器主体区域 -->
    <div class="play_wrap" id="player">
      <div class="search_bar">
        <img src="images/player_title.png" alt="" />
        <!-- 搜索歌曲 -->
        <input type="text" v-model="keywords" autocomplete="off" @keyup.enter="getMusicList();"/>
      </div>
      <div class="center_con">
        <!-- 搜索歌曲列表 -->
        <div class='song_wrapper'>
          <ul class="song_list">
            <li v-for="item in musicList">
              <!-- 播放按钮 -->
              <a href="javascript:;" @click="choiceMusic(item)"></a> 
              <!-- 歌曲名字 -->
              <b>{{item.name}}--{{item.artists[0].name}}</b> 
              <!-- mv按钮 -->
              <span v-show="item.mvid!=0"><i @click="getMiscMv(item.mvid)"></i></span>
            </li>
          </ul>
          <img src="images/line.png" class="switch_btn" alt="">
        </div>
        <!-- 歌曲信息容器 -->
        <div class="player_con">
          <img src="images/player_bar.png" class="play_bar" />
          <!-- 黑胶碟片 -->
          <img src="images/disc.png" class="disc autoRotate" />
          <img  class="cover autoRotate" />
        </div>

        <!-- 评论容器 213-->
        <div class="comment_wrapper">
          <h5 class='title'>热门留言</h5>
          <div class='comment_list'>
            <dl v-for="item in hotCommentList">
              <dt><img :src="item.user.avatarUrl" alt=""></dt>
              <dd class="name">{{ item.nickname}}</dd>
              <dd class="detail">
                {{ item.content }}
              </dd>
            </dl>
          </div>
          <img src="images/line.png" class="right_line">
        </div>
      </div>
      <!-- 底部的音乐播放 -->
      <div class="audio_con">
        <audio controls class="myaudio" :src="choiceMusicUrl" autoplay="autoplay"></audio>
      </div>
      <!-- mv -->
      <div class="video_con" v-if="vedioFlag">
        <video controls="controls" id="mvVideo"></video>
        <div class="mask" @click="dispVedio"></div>
      </div>
    </div>
  </div>
  <!-- 开发环境版本，包含了有帮助的命令行警告 -->
  <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
  <!-- jquery -->
  <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.4/jquery.js"></script>
  <!-- 官网提供的 axios 在线地址 -->
  <!-- <script src="https://unpkg.com/axios/dist/axios.min.js"></script> -->
  <!-- <script src="./js/main.js"></script> -->
</body>


<script>
    var app = new Vue({
      el:"#player",

      data:{
        musicList :[],
        keywords:"",              // 搜索的关键字
        choiceMusicClass:"",      //点击播放的音乐对象
        hotCommentList:[],        //热评对象列表
        choiceMusicUrl:"",        //点击播放的音乐资源
        musicPicUrl:"images/disc.png",
        mvUrl:"",
        vedioFlag:false
      },

      methods: {
        //根据关键字获取歌单
        getMusicList:function(){

          var that = this;

          $.ajax({
            url:"https://autumnfish.cn/search?keywords="+that.keywords,
            type:"get",
            success:function(res){
                if(res.code!=200){
                    alert("搜索失败，请稍后重试");
                    return;
                }
                //歌曲信息放到data中
                that.musicList = res.result.songs;
                console.log(that.musicList);
            },
            error:function(error){

            }
          });
        },
      

        //选择的音乐
        choiceMusic:function(item){
            this.choiceMusicClass = item;
            //加载热评
            this.getHotComment();
            //加载音乐
            this.playMuisc();
            //歌曲详细信息，包括封面
            this.getMusicDetails();
        },
      


        //获取热评
        getHotComment:function(){
          
          var that = this;
          var id = that.choiceMusicClass.id;

          $.ajax({
            url:"https://autumnfish.cn/comment/hot?type=0&id="+id,
            type:"get",
            success:function(res){
                if(res.code!=200){
                    alert("热评获取失败，请稍后重试");
                    return;
                }
                //热评放到data中
                that.hotCommentList = res.hotComments;
              
            },
            error:function(error){

            }
          });
        },
      
      

        //获取音乐资源  https://autumnfish.cn/song/url 音乐的url
        playMuisc:function(){
          var that = this;
          var music = that.choiceMusicClass;
          $.ajax({
            url:"https://autumnfish.cn/song/url?id="+music.id,
            type:'get',
            success:function(res){
              if(res.code!=200){
                  alert("音乐资源获取失败，请稍后重试");
              }
                that.choiceMusicUrl = res.data[0].url;
            },
            error:function(){

            },
          });
        },
      
      

        
        //歌曲信息，包括封面
        getMusicDetails:function(){
          var that = this;
          var ids = that.choiceMusicClass.id;
          
          $.ajax({
            url:'https://autumnfish.cn/song/detail?ids='+ids,
            type:'get',
            success:function(res){
                if(res.code!=200){
                    alert("歌曲详细信息获取失败，请稍后重试");
                }
                //封面照片
                that.musicPicUrl = res.songs[0].al.picUrl;
                console.log(that.musicPicUrl);
            },
            error:function(){

            }
          });
        },
      
      

        //获取音乐mv
        getMiscMv:function(mvid){
            var that = this;
            this.vedioFlag = true;
            var id = mvid;
            $.ajax({
              url:"https://autumnfish.cn/mv/url?id="+id,
              type:"get",
              success:function(res){
                if(res.code!=200){
                    alert("mv 获取失败，请稍后重试");
                }
                //mv地址放到data中
                that.mvUrl = res.data.url;
                //操作视频播放标签
                $('.video_con').css("display","");
                $('#mvVideo').attr("src",that.mvUrl);
                $('#mvVideo').attr("controls","controls");
              }
            });
        },
      
        

        //隐藏vedio标签
        dispVedio:function(){
          this.vedioFlag = false;
        }
      },
    });
</script>
</html>


music id 2011072415
mv id 14535058